<template>
  <div>
    <h1>tab选项卡</h1>

    <el-tabs>
      <el-tab-pane label="未读消息" name="first">
        <div
          v-for="(item, index) in list"
          :key="index"
          v-show="item.status == 0"
        >
          <div class="wrap">
            <span>{{ item.title }}</span>
            <el-button @click="change1(item)">标记已读</el-button>
          </div>

          <el-divider></el-divider>
        </div>
        <el-button @click="allDoen">全部标为已读</el-button>
      </el-tab-pane>

      <el-tab-pane label="已读消息" name="second">
        <div
          v-for="(item, index) in list"
          :key="index"
          v-show="item.status == 1"
        >
          <div class="wrap">
            <span>{{ item.title }}</span>
            <div>
              <el-button @click="item.status = 2">删除</el-button>
              <el-button @click="item.status = 0">还原未读</el-button>
            </div>
          </div>

          <span>{{ item.title }}</span>
          <el-divider></el-divider>
        </div>
        <el-button @click="allchange">全部放入回收站</el-button>
      </el-tab-pane>
      <el-tab-pane label="回收站" name="third">
        <div
          v-for="(item, index) in list"
          :key="index"
          v-show="item.status == 2"
        >
          <div class="wrap">
            <span>{{ item.title }}</span>
            <el-button @click="item.status = 1">还原未读 </el-button>
          </div>

          <span>{{ item.title }}</span>
          <el-divider></el-divider>
        </div>
        <el-button @click="allremove">全部删除</el-button>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
export default {
  data() {
    return {
      list: JSON.parse(localStorage.getItem("list")) || [
        {
          title: "任务1",
          status: "0",
        },
        {
          title: "任务2",
          status: "1",
        },
        {
          title: "任务3",
          status: "2",
        },
        {
          title: "任务4",
          status: "0",
        },
        {
          title: "任务5",
          status: "1",
        },
        {
          title: "任务6",
          status: "2",
        },
      ],
    };
  },
  mounted() {
    localStorage.setItem("list",JSON.stringify(this.list));
  },
  methods: {
    save() {
      localStorage.setItem("list", JSON.stringify(this.list));
    },
  },
  methods: {
    save() {
      localStorage.setItem("list", this.list);
    },
    allDoen() {
      this.list.forEach((item) => {
        if (item.status == 0) {
          item.status = 1;
        }
      });
      this.save();
    },
    change1(item) {
      item.status = 1;
      this.save();
    },
    allchange() {
      this.list.forEach((item) => {
        if (item.status == 1) {
          item.status = 2;
        }
      });
      this.save();
    },
    allremove() {
      this.list.forEach((item) => {
        if (item.status == 2) {
          item.status = -1;
        }
      });
      this.save();
    },
    
  },
};
</script>

<style lang="scss">
.wrap {
  display: flex;
  justify-content: space-between;
}
</style>
